import requests
import os


def download_img(url_info):
    try:
        url = url_info
        header = {
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.75 Safari/537.36"
        }
        response = requests.get(url, headers=header)
        img = response.content
        imgname = str(url).split("/")[-1]
        # Save Path
        path = r'C:\Users\12274\PycharmProjects\HW1\HW\imgs\%s' % imgname
        if os.path.exists(path):
            print(f"----------exits----{imgname}")
        else:
            with open(path, 'wb') as f:
                f.write(img)
            print(f"----------success----{imgname}")
        response.close()

    except Exception as ex:
        print("--------Error----")
        pass


